package week08;

import java.awt.List;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

interface GeneralStack<T>
{
	 public T push(T item);
     
	 public T pop();

	 public T peek();

	 public boolean empty();

	 public int size();     
}

class ArrayListGeneralStack<T> implements GeneralStack<T> {
	ArrayList<T> list=new ArrayList<T>();

	@Override
	public T push(T item) {
		// TODO Auto-generated method stub
		if(item==null)
		   return null;
	    list.add(item);
		return item;
	}

	@Override
	public T pop() {
		// TODO Auto-generated method stub
		if(list.isEmpty())
		  return null; 
		return list.remove(list.size()-1);
	}

	@Override
	public T peek() {
		// TODO Auto-generated method stub
		if(list.isEmpty())
		  return null; 
		return list.get(list.size()-1);
	}

	@Override
	public boolean empty() {
		// TODO Auto-generated method stub
		return list.isEmpty();
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public String toString() {
		return list.toString();
	}

}
class Car
{
	private int id;
	private String name;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	public Car(int id, String name) {
		super();
		this.id = id;
		this.name = name;
	}
	@Override
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}
	
}
public class Main1 {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		while(true)
		{
			switch(in.nextLine())
			{
			case "Integer":
				System.out.println("Integer Test");
				ArrayListGeneralStack<Integer> list1=new ArrayListGeneralStack<Integer>();
				int m=Integer.parseInt(in.nextLine());
				int n=Integer.parseInt(in.nextLine());
				ArrayList<Integer> a=new ArrayList<Integer>();
				 for(int i = 0; i <m; i++) {
				    	a.add(in.nextInt());
				    }
				    for(int i = 0; i <m; i++) {
				    	list1.push(a.get(i));
						System.out.println("push:"+a.get(i));
				    }
				    for (int i = 0; i < n; i++) {
				    	if(i<=m)
				    	{
						System.out.println("pop:"+list1.pop());
				    	}
					}
				    System.out.println(list1.toString());
				    int sum=0;
				    while(!list1.empty())
				    {
						 sum+=list1.pop();
				    }
				    System.out.println("sum="+sum);
				    System.out.println(list1.getClass().getInterfaces()[0]);
				break;
            case "Double":
            	System.out.println("Double Test");
				ArrayListGeneralStack<Double> list2=new ArrayListGeneralStack<Double>();
				int p=Integer.parseInt(in.nextLine());
				int q=Integer.parseInt(in.nextLine());
			    ArrayList<Double> b=new ArrayList<Double>();
			    for(int i = 0; i <p; i++) {
			    	b.add(in.nextDouble());
			    }
			    for(int i = 0; i <p; i++) {
			    	list2.push(b.get(i));
					System.out.println("push:"+b.get(i));
				}
			    for (int i = 0; i < q; i++) {
			    	if(i<=p) {
					System.out.println("pop:"+list2.pop());
			    	}
				}
			    System.out.println(list2.toString());
			    double sum1=0;
			    while(!list2.empty()) {
					 sum1+=list2.pop();
			      }
					 System.out.println("sum="+sum1);
			    System.out.println(list2.getClass().getInterfaces()[0]);
				break;
            case "Car":
            	System.out.println("Car Test");
            	ArrayListGeneralStack<Car> list3=new ArrayListGeneralStack<Car>();
            	int s=Integer.parseInt(in.nextLine());
				int t=Integer.parseInt(in.nextLine());
				ArrayList<Car> c=new ArrayList<>();
				for(int i = 0; i <s; i++) {
					String[] str=in.nextLine().split(" ");
                    c.add(new Car(Integer.parseInt(str[0]),str[1]));
			    }
			    for(int i = 0; i <s; i++) {
			    	list3.push(c.get(i));
					System.out.println("push:"+c.get(i));
				}
			    for (int i = 0; i < t; i++) {
			    	if(i<=s)
			    	{
					System.out.println("pop:"+list3.pop());
					c.remove(list3.size());
			    	}
				}
			    System.out.println(list3.toString());
			    while(!list3.empty()) {
			    	System.out.println(list3.pop().getName());
			    }
			    System.out.println(list3.getClass().getInterfaces()[0]);
				break;
            case "quit":
				break;
			default:
				break;
			}
	
		}
	}

}
